<template>
  <div class="picture-generation-container">
    <a-card title="AI图片生成" class="section-card">
      <a-row :gutter="24">
        <a-col :span="12">
          <a-form layout="vertical">
            <a-form-item label="图片描述">
              <a-textarea
                v-model:value="genParam.prompt"
                placeholder="请输入您想要生成的图片描述，例如：一只可爱的小猫在花园里玩耍"
                :rows="4"
                show-count
                :maxlength="500"
              />
            </a-form-item>

            <a-form-item label="图片比例">
              <a-select v-model:value="genParam.resolution" style="width: 100%">
                <a-select-option value="1024*1024">
                  <div class="ratio-option">
                    <span class="ratio-name">1:1(正方形)</span>
                    <span class="ratio-desc">头像、图标、社交媒体</span>
                  </div>
                </a-select-option>
                <a-select-option value="1440*810">
                  <div class="ratio-option">
                    <span class="ratio-name">16:9 (宽屏)</span>
                    <span class="ratio-desc">PPT背景、网站横幅、视频封面</span>
                  </div>
                </a-select-option>
                <a-select-option value="810*1440">
                  <div class="ratio-option">
                    <span class="ratio-name">9:16 (竖屏)</span>
                    <span class="ratio-desc">手机壁纸、社交媒体故事</span>
                  </div>
                </a-select-option>
                <a-select-option value="1440*1080">
                  <div class="ratio-option">
                    <span class="ratio-name">4:3 (标准)</span>
                    <span class="ratio-desc">演示文稿、传统照片</span>
                  </div>
                </a-select-option>
                <a-select-option value="1440*960">
                  <div class="ratio-option">
                    <span class="ratio-name">3:2 (摄影)</span>
                    <span class="ratio-desc">摄影作品、打印照片</span>
                  </div>
                </a-select-option>
              </a-select>
            </a-form-item>

            <a-form-item label="图片数量">
              <a-input-number
                v-model:value="genParam.count"
                :min="1"
                :max="4"
                style="width: 100%"
              />
            </a-form-item>

            <a-form-item label="图片风格">
              <a-select v-model:value="genParam.style" style="width: 100%">
                <a-select-option value="中国风">
                  <div class="style-option">
                    <img src="@/assets/style/中国风.webp" alt="中国风" class="style-preview" />
                    <span>中国风</span>
                  </div>
                </a-select-option>
                <a-select-option value="二次元">
                  <div class="style-option">
                    <img src="@/assets/style/二次元.webp" alt="二次元" class="style-preview" />
                    <span>二次元</span>
                  </div>
                </a-select-option>
                <a-select-option value="人像摄影">
                  <div class="style-option">
                    <img src="@/assets/style/人像摄影.webp" alt="人像摄影" class="style-preview" />
                    <span>人像摄影</span>
                  </div>
                </a-select-option>
                <a-select-option value="像素风格">
                  <div class="style-option">
                    <img src="@/assets/style/像素风格.webp" alt="像素风格" class="style-preview" />
                    <span>像素风格</span>
                  </div>
                </a-select-option>
                <a-select-option value="卡通">
                  <div class="style-option">
                    <img src="@/assets/style/卡通.webp" alt="卡通" class="style-preview" />
                    <span>卡通</span>
                  </div>
                </a-select-option>
                <a-select-option value="古典">
                  <div class="style-option">
                    <img src="@/assets/style/古典.webp" alt="古典" class="style-preview" />
                    <span>古典</span>
                  </div>
                </a-select-option>
                <a-select-option value="复古动漫">
                  <div class="style-option">
                    <img src="@/assets/style/复古动漫.webp" alt="复古动漫" class="style-preview" />
                    <span>复古动漫</span>
                  </div>
                </a-select-option>
                <a-select-option value="巴洛克">
                  <div class="style-option">
                    <img src="@/assets/style/巴洛克.webp" alt="巴洛克" class="style-preview" />
                    <span>巴洛克</span>
                  </div>
                </a-select-option>
                <a-select-option value="水墨画">
                  <div class="style-option">
                    <img src="@/assets/style/水墨画.webp" alt="水墨画" class="style-preview" />
                    <span>水墨画</span>
                  </div>
                </a-select-option>
                <a-select-option value="电影写真">
                  <div class="style-option">
                    <img src="@/assets/style/电影写真.webp" alt="电影写真" class="style-preview" />
                    <span>电影写真</span>
                  </div>
                </a-select-option>
                <a-select-option value="绘本">
                  <div class="style-option">
                    <img src="@/assets/style/绘本.webp" alt="绘本" class="style-preview" />
                    <span>绘本</span>
                  </div>
                </a-select-option>
                <a-select-option value="赛博朋克">
                  <div class="style-option">
                    <img src="@/assets/style/赛博朋克.webp" alt="赛博朋克" class="style-preview" />
                    <span>赛博朋克</span>
                  </div>
                </a-select-option>
              </a-select>
            </a-form-item>

            <a-form-item>
              <a-button type="primary" :loading="generating" @click="generateImage" block>
                生成图片
              </a-button>
            </a-form-item>
          </a-form>
        </a-col>

        <a-col :span="12">
          <div class="result-section">
            <h3>生成结果</h3>

            <!-- 加载状态 -->
            <div v-if="loading" class="loading-container">
              <div class="loading-grid" :class="`loading-count-${count}`">
                <div
                  v-for="index in count"
                  :key="index"
                  class="loading-placeholder"
                  :style="{ animationDelay: `${(index - 1) * 0.2}s` }"
                >
                  <div class="loading-shimmer"></div>
                  <div class="loading-progress">
                    <div class="progress-bar"></div>
                  </div>
                  <div class="loading-text">生成中 {{ index }}/{{ count }}</div>
                </div>
              </div>
              <div class="loading-status">
                <div class="status-icon">
                  <div class="magic-wand">
                    <div class="wand-body"></div>
                    <div class="wand-star"></div>
                    <div class="sparkles">
                      <div class="sparkle"></div>
                      <div class="sparkle"></div>
                      <div class="sparkle"></div>
                    </div>
                  </div>
                </div>
                <p class="status-text">AI正在为您创作精美图片...</p>
                <div class="loading-dots"><span></span><span></span><span></span></div>
              </div>
            </div>

            <!-- 生成结果 -->
            <div
              v-else-if="generatedImages.length > 0"
              class="images-grid"
              :class="`grid-count-${generatedImages.length}`"
            >
              <div
                v-for="(image, index) in generatedImages"
                :key="index"
                class="image-item"
                :style="{ animationDelay: `${index * 0.1}s` }"
              >
                <div class="image-wrapper">
                  <img :src="image.url" :alt="`Generated image ${index + 1}`" />
                  <div class="image-overlay">
                    <div class="image-number">{{ index + 1 }}</div>
                  </div>
                </div>
                <div class="image-actions">
                  <a-button
                    type="primary"
                    size="small"
                    @click="downloadImage(image.url, `generated-image-${index + 1}`)"
                    class="download-btn"
                  >
                    <template #icon>
                      <svg viewBox="0 0 24 24" width="14" height="14" fill="currentColor">
                        <path d="M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z" />
                      </svg>
                    </template>
                    下载
                  </a-button>
                  <a-button size="small" @click="previewImage(image.url)" class="preview-btn">
                    <template #icon>
                      <svg viewBox="0 0 24 24" width="14" height="14" fill="currentColor">
                        <path
                          d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"
                        />
                      </svg>
                    </template>
                    预览
                  </a-button>
                </div>
              </div>
            </div>

            <!-- 空状态 -->
            <div v-else class="empty-state">
              <div class="empty-icon">
                <svg viewBox="0 0 64 64" width="48" height="48">
                  <circle
                    cx="32"
                    cy="32"
                    r="30"
                    fill="none"
                    stroke="#e0e6ff"
                    stroke-width="2"
                    stroke-dasharray="5,5"
                  >
                    <animateTransform
                      attributeName="transform"
                      type="rotate"
                      values="0 32 32;360 32 32"
                      dur="10s"
                      repeatCount="indefinite"
                    />
                  </circle>
                  <path
                    d="M32 16v32M16 32h32"
                    stroke="#c7d2fe"
                    stroke-width="2"
                    stroke-linecap="round"
                  />
                  <circle cx="32" cy="32" r="4" fill="#667eea" />
                </svg>
              </div>
              <h4>等待创作</h4>
              <p>输入描述并点击生成按钮，AI将为您创作精美图片</p>
            </div>
          </div>
          <span style="color: rgb(122, 133, 128)"
            >温馨提示：图片最好当即下载，系统只保存24小时</span
          >
        </a-col>
      </a-row>
    </a-card>

    <!-- 图片预览模态框 -->
    <a-modal
      v-model:open="previewVisible"
      title="图片预览"
      :footer="null"
      :width="800"
      centered
      @cancel="handlePreviewCancel"
    >
      <div class="preview-container">
        <a-image
          :src="previewImageUrl"
          :preview="false"
          style="width: 100%; max-height: 70vh; object-fit: contain"
        />
      </div>
    </a-modal>
  </div>
</template>

<script lang="ts" setup>
import { ref, reactive } from 'vue'
import { message } from 'ant-design-vue'
import { saveAs } from 'file-saver'
import { genPictureByText } from '@/api/multiModalGenController'

const prompt = ref('')
const count = ref(1)
const generating = ref(false)
const loading = ref(false)
const generatedImages = ref<Array<{ url: string }>>([])
const previewVisible = ref(false)
const previewImageUrl = ref('')

// 图片生成相关
const genParam = reactive<API.GenPictureRequest>({
  prompt: '',
  count: 1,
  resolution: '1024*1024',
  style: '',
})
const generateImage = async () => {
  prompt.value = genParam?.prompt ?? ''
  count.value = genParam?.count ?? 1
  if (!prompt.value.trim()) {
    message.warning('请输入图片描述')
    return
  }

  generating.value = true
  loading.value = true

  try {
    const res = await genPictureByText({
      ...genParam,
    })
    if (res.data.data && res.data.code === 0) {
      generatedImages.value = res.data.data.map((item, index) => ({
        url: item,
      }))
      message.success('图片生成成功！')
    }
    // 模拟API调用，实际项目中需要替换为真实的API端点
    // await new Promise((resolve) => setTimeout(resolve, 2000))

    // 根据比例计算实际尺寸
    // const sizeMap = {
    //   '1:1': '512x512',
    //   '16:9': '1024x576',
    //   '9:16': '576x1024',
    //   '4:3': '1024x768',
    //   '3:2': '1024x683',
    // }
    //
    // const actualSize = sizeMap[aspectRatio.value as keyof typeof sizeMap] || '512x512'
    // 模拟生成的图片数据
    // const mockImages = Array(count.value)
    //   .fill(null)
    //   .map((_, index) => ({
    //     url: `https://picsum.photos/${actualSize.replace('x', '/')}?random=${Date.now() + index}`,
    //     filename: `generated-image-${Date.now()}-${index + 1}.jpg`,
    //   }))
    // const mockImages = Array(count.value)
    //   .fill(null)
    //   .map((_, index) => ({
    //     // url: "https://dashscope-result-wlcb-acdr-1.oss-cn-wulanchabu-acdr-1.aliyuncs.com/1d/94/20250806/7c732c4a/3dc0c0e8-c649-4681-9876-43d851266ced1327915954.png?Expires=1754553557&OSSAccessKeyId=LTAI5tKPD3TMqf2Lna1fASuh&Signature=%2FZLfBL71b9zXkzV8wR53cuxzKcs%3D",
    //     url:"https://dashscope-result-wlcb-acdr-1.oss-cn-wulanchabu-acdr-1.aliyuncs.com/1d/1d/20250806/7c732c4a/eec26c49-a9e6-424a-bfd8-dd10b6c3697b3169107603.png?Expires=1754553872&OSSAccessKeyId=LTAI5tKPD3TMqf2Lna1fASuh&Signature=SycuA6dW26StlgH2RZOyVgCyMlg%3D",
    //   }))
    //
    // generatedImages.value = mockImages
  } catch (error) {
    message.error('生成失败，请重试')
    console.error('Image generation error:', error)
  } finally {
    generating.value = false
    loading.value = false
  }
}

const downloadImage = async (url: string, filename: string) => {
  try {
    // 显示下载进度
    const loadingMessage = message.loading('正在下载图片...', 0)

    // 创建一个临时的a标签进行下载，避免跨域问题
    const link = document.createElement('a')
    link.href = url
    link.download = filename
    link.target = '_blank'

    // 添加到DOM并触发点击
    document.body.appendChild(link)
    link.click()
    document.body.removeChild(link)

    // 关闭加载提示
    loadingMessage()
    message.success('图片下载成功')
  } catch (error) {
    message.error('下载失败，请重试')
    console.error('Download error:', error)
  }
}

const previewImage = (url: string) => {
  try {
    // 使用Ant Design的模态框和图像组件
    previewImageUrl.value = url
    previewVisible.value = true
  } catch (error) {
    message.error('预览失败，请重试')
    console.error('Preview error:', error)
  }
}

const handlePreviewCancel = () => {
  previewVisible.value = false
}
</script>

<style scoped>
.picture-generation-container {
  padding: 24px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  background-size: cover;
  background-blend-mode: overlay;
  height: 90vh;
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}

.picture-generation-container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background:
    radial-gradient(circle at 30% 20%, rgba(102, 126, 234, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 70% 80%, rgba(118, 75, 162, 0.1) 0%, transparent 50%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.9) 0%, rgba(248, 250, 255, 0.85) 100%);
  z-index: 0;
}

/* 移除复杂的旋转动画以减少卡顿 */

.section-card {
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.98) 0%, rgba(248, 250, 255, 0.95) 100%);
  border-radius: 24px;
  box-shadow:
    0 8px 32px rgba(102, 126, 234, 0.12),
    0 4px 16px rgba(0, 0, 0, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.4);
  backdrop-filter: blur(20px);
  z-index: 1;
  position: relative;
  transition: box-shadow 0.2s ease;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.section-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
  z-index: 1;
}

.section-card:hover {
  box-shadow:
    0 8px 24px rgba(102, 126, 234, 0.12),
    0 4px 16px rgba(0, 0, 0, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

:deep(.ant-card) {
  height: 100%;
  display: flex;
  flex-direction: column;
}

:deep(.ant-card-body) {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

:deep(.ant-row) {
  flex: 1;
  display: flex;
}

:deep(.ant-col) {
  display: flex;
  flex-direction: column;
}

:deep(.ant-card-head) {
  border-bottom: 1px solid rgba(102, 126, 234, 0.2);
  background: transparent;
  flex-shrink: 0;
}

:deep(.ant-card-head-title) {
  font-size: 18px;
  font-weight: 600;
  color: #2c3e50;
}

:deep(.ant-form-item-label > label) {
  font-weight: 500;
  color: #2c3e50;
}

:deep(.ant-input),
:deep(.ant-input-affix-wrapper),
:deep(.ant-select-selector) {
  border-radius: 12px;
  border: 2px solid rgba(102, 126, 234, 0.1);
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.95) 0%, rgba(248, 250, 255, 0.9) 100%);
  transition: border-color 0.2s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

:deep(.ant-input:hover),
:deep(.ant-input-affix-wrapper:hover),
:deep(.ant-select-selector:hover) {
  border-color: rgba(102, 126, 234, 0.4);
}

:deep(.ant-input:focus),
:deep(.ant-input-affix-wrapper:focus),
:deep(.ant-select-focused .ant-select-selector) {
  border-color: #667eea;
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
  background: rgba(255, 255, 255, 0.98);
}

:deep(.ant-textarea) {
  border-radius: 12px;
  border: 2px solid rgba(102, 126, 234, 0.1);
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.95) 0%, rgba(248, 250, 255, 0.9) 100%);
  transition: border-color 0.2s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

:deep(.ant-textarea:hover) {
  border-color: rgba(102, 126, 234, 0.4);
}

:deep(.ant-textarea:focus) {
  border-color: #667eea;
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
  background: rgba(255, 255, 255, 0.98);
}

:deep(.ant-btn-primary) {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  border-radius: 16px;
  height: 52px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
  transition: background 0.2s ease;
}

:deep(.ant-btn-primary:hover) {
  background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
}

:deep(.ant-btn-primary:active) {
  background: linear-gradient(135deg, #4f63d2 0%, #5d3a84 100%);
}

/* 上传预览样式 */
.uploaded-preview {
  margin-top: 12px;
  padding: 12px;
  background: #f5f5f5;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.uploaded-preview img {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 6px;
}

/* 比例选择样式 */
.ratio-option {
  display: flex;
  flex-direction: column;
  padding: 4px 0;
}

.ratio-name {
  font-weight: 500;
  color: #333;
  font-size: 14px;
}

.ratio-desc {
  font-size: 12px;
  color: #666;
  margin-top: 2px;
}

/* 风格选择样式 */
.style-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 0;
}

.style-preview {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  object-fit: cover;
}

.style-option span {
  font-size: 14px;
  color: #333;
}

.result-section {
  padding: 28px;
  background: linear-gradient(145deg, rgba(248, 250, 255, 0.95) 0%, rgba(240, 245, 255, 0.9) 100%);
  border-radius: 20px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  flex: 1;
  z-index: 1;
  position: relative;
  box-shadow:
    0 8px 32px rgba(102, 126, 234, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  transition: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.result-section::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
  border-radius: 20px 20px 0 0;
}

.result-section h3 {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, #2c3e50 0%, #667eea 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 24px;
  text-align: center;
  position: relative;
}

.result-section h3::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 3px;
  background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
  border-radius: 2px;
}

/* 加载状态样式 */
.loading-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  overflow-y: auto;
}

.loading-grid {
  display: grid;
  gap: 16px;
  margin-bottom: 32px;
}

.loading-grid.loading-count-1 {
  grid-template-columns: 1fr;
}

.loading-grid.loading-count-2 {
  grid-template-columns: repeat(2, 1fr);
}

.loading-grid.loading-count-3 {
  grid-template-columns: repeat(3, 1fr);
}

.loading-grid.loading-count-4 {
  grid-template-columns: repeat(2, 1fr);
}

.loading-placeholder {
  position: relative;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.9) 0%, rgba(248, 250, 255, 0.8) 100%);
  border-radius: 16px;
  border: 2px solid rgba(102, 126, 234, 0.1);
  height: 200px;
  overflow: hidden;
  opacity: 1;
}

.loading-shimmer {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(102, 126, 234, 0.1);
}

.loading-progress {
  position: absolute;
  bottom: 40px;
  left: 16px;
  right: 16px;
  height: 4px;
  background: rgba(102, 126, 234, 0.1);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #667eea, #764ba2);
  border-radius: 2px;
  width: 60%;
}

.loading-text {
  position: absolute;
  bottom: 12px;
  left: 16px;
  right: 16px;
  text-align: center;
  font-size: 12px;
  color: #667eea;
  font-weight: 500;
}

.loading-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
}

.status-icon {
  margin-bottom: 24px;
}

.magic-wand {
  position: relative;
  width: 60px;
  height: 60px;
}

.wand-body {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 4px;
  background: linear-gradient(90deg, #8b4513, #d2691e);
  border-radius: 2px;
  transform: translate(-50%, -50%) rotate(45deg);
}

.wand-star {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 16px;
  height: 16px;
  background: linear-gradient(45deg, #ffd700, #ffa500);
  clip-path: polygon(
    50% 0%,
    61% 35%,
    98% 35%,
    68% 57%,
    79% 91%,
    50% 70%,
    21% 91%,
    32% 57%,
    2% 35%,
    39% 35%
  );
}

.sparkles {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

.sparkle {
  position: absolute;
  width: 6px;
  height: 6px;
  background: #667eea;
  border-radius: 50%;
  opacity: 0.5;
}

.sparkle:nth-child(1) {
  top: 20%;
  left: 20%;
}

.sparkle:nth-child(2) {
  top: 60%;
  right: 20%;
}

.sparkle:nth-child(3) {
  bottom: 20%;
  left: 60%;
}

.status-text {
  font-size: 16px;
  color: #2c3e50;
  font-weight: 500;
  margin-bottom: 16px;
  text-align: center;
}

.loading-dots {
  display: flex;
  gap: 8px;
}

.loading-dots span {
  width: 8px;
  height: 8px;
  background: #667eea;
  border-radius: 50%;
  opacity: 0.7;
}

.loading-dots span:nth-child(1) {
  opacity: 1;
}
.loading-dots span:nth-child(2) {
  opacity: 0.7;
}
.loading-dots span:nth-child(3) {
  opacity: 0.4;
}

/* 图片网格样式 */
.images-grid {
  flex: 1;
  display: grid;
  gap: 20px;
  padding: 8px;
  overflow-y: auto;
  align-content: start;
}

.images-grid.grid-count-1 {
  grid-template-columns: 1fr;
  max-width: 400px;
  margin: 0 auto;
}

.images-grid.grid-count-2 {
  grid-template-columns: repeat(2, 1fr);
}

.images-grid.grid-count-3 {
  grid-template-columns: repeat(3, 1fr);
}

.images-grid.grid-count-4 {
  grid-template-columns: repeat(2, 1fr);
}

.image-item {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.1);
  height: 280px;
  transition: none;
  cursor: pointer;
  opacity: 1;
}

.image-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: 11px;
}

.image-overlay {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
}

.image-number {
  width: 32px;
  height: 32px;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.image-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-actions {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
  display: flex;
  justify-content: center;
  gap: 12px;
  opacity: 1;
}

.download-btn,
.preview-btn {
  border-radius: 8px;
  font-weight: 500;
  transition: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.download-btn {
  background: #667eea;
  border: none;
  color: white;
}

.download-btn:hover {
  background: #5a6fd8;
}

.preview-btn {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #2c3e50;
}

.preview-btn:hover {
  background: rgba(255, 255, 255, 1);
}

.image-actions .ant-btn {
  background: linear-gradient(135deg, #667eea, #764ba2);
  border: none;
  border-radius: 6px;
  font-weight: 500;
  transition: none;
}

.image-actions .ant-btn:hover {
  background: linear-gradient(135deg, #5a6fd8, #6a4190);
}

/* 空状态样式 */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 40px;
  background: linear-gradient(145deg, rgba(248, 250, 255, 0.8) 0%, rgba(240, 245, 255, 0.6) 100%);
  border-radius: 20px;
  border: 2px dashed rgba(102, 126, 234, 0.2);
}

.empty-icon {
  margin-bottom: 24px;
}

.empty-state h4 {
  font-size: 18px;
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 14px;
  color: #64748b;
  text-align: center;
  line-height: 1.5;
  max-width: 280px;
}

/* 预览容器样式 */
.preview-container {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px 0;
}

/* 响应式优化 */
@media (max-width: 1200px) {
  .picture-generation-container {
    padding: 16px;
  }

  .section-card {
    border-radius: 12px;
  }

  .images-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
  }
}

@media (max-width: 768px) {
  .picture-generation-container {
    padding: 12px;
  }

  .section-card {
    border-radius: 8px;
  }

  .images-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .image-item {
    height: 250px;
  }

  :deep(.ant-btn-primary) {
    height: 40px;
    font-size: 13px;
  }

  .ratio-option,
  .style-option {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* 深色模式适配 */
@media (prefers-color-scheme: dark) {
  .picture-generation-container::before {
    background-color: rgba(0, 0, 0, 0.7);
  }

  .section-card {
    background: rgba(30, 30, 30, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.1);
  }

  :deep(.ant-card-head-title) {
    color: #fff;
  }

  :deep(.ant-form-item-label > label) {
    color: #fff;
  }

  :deep(.ant-input),
  :deep(.ant-input-affix-wrapper),
  :deep(.ant-select-selector),
  :deep(.ant-textarea) {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    color: #fff;
  }

  .result-section {
    background: rgba(40, 40, 40, 0.9);
  }

  .result-section h3 {
    color: #fff;
  }

  .empty-state {
    background: rgba(40, 40, 40, 0.9);
    border-color: rgba(102, 126, 234, 0.5);
  }

  .uploaded-preview {
    background: rgba(255, 255, 255, 0.1);
  }

  .ratio-name,
  .style-option span {
    color: #fff;
  }

  .ratio-desc {
    color: #ccc;
  }
}
</style>
